import { BaseWindow } from "../../../component/window/BaseWindow";
import { ILayer } from "../../../mvc/interfaces/ILayer";
import { Language } from "../../../../extend/language/Language";
import { WindowEvent } from "../../../component/window/WindowEvent";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { EGuildwarState } from "./defin/EGuildwarState";
import { Cache } from "../../cache/Cache";
import { ClockManager } from "../../manager/ClockManager";
import { SGuildWarSingUpInfo } from "../../../../Message/Public/SGuildWarSingUpInfo";
import { GuildwarSignListWindow } from "./GuildwarSignListWindow";
import { LoaderHelp } from "../../../common/display/LoaderHelp";
import { ResFileConst } from "../../resource/ResFileConst";
import { ObjCreate } from "../common/ObjCreate";
import { GTextFormat } from "../../../common/GTextFormat";
import { FontUtil } from "../../../common/font/FontUtil";
import { GlobalClass } from "../../../../com/mui/core/GlobalClass";
import { ImagesConst } from "../../resource/ImagesConst";
import { GlobalStyle } from "../../../common/global/GlobalStyle";
import { ObjTeamCreate } from "../common/ObjTeamCreate";
import { BgItem } from "../common/BgItem";
import { AIManager } from "../../scene/ai/AIManager";
import { ENpcEffect } from "../../../../Message/Public/ENpcEffect";
import { AIType } from "../../scene/ai/AIType";
import { ItemData } from "../../resource/info/ItemData";
import { ItemsUtil } from "../shortcuts/item/ItemsUtil";
import { SecTimerView } from "../common/SecTimerView";
import { GButton } from "../../../../com/mui/controls/GButton";
type int = number;
//class GuildwarEnterWindow
    
    export  class GuildwarEnterWindow extends BaseWindow
    {
        constructor(arg1: ILayer=null)
        {
            super(arg1);
            this._bmpRank1 = new Object /* flash.display.Bitmap */();
            this._bmpRank23 = new Object /* flash.display.Bitmap */();
            this._bmpRank45 = new Object /* flash.display.Bitmap */();
            this._bmpContributeImg = new Object /* flash.display.Bitmap */();
            this._bmpGuildContribute = new Object /* flash.display.Bitmap */();
            setSize(643, 472);
            titleHeight = 26;
            title = Language.getString(41858);
            this.addEventListener(WindowEvent.CLOSE, this.onClose);
            this.addEventListener(flash.events.Event.ADDED_TO_STAGE, this.onAdd);
            return;
        }

        /* internal  */onAdd(arg1: Object /* flash.events.Event */): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.GuildWarIsNotice, true));
            return;
        }

        /* internal  */onClose(arg1: Object /* flash.events.Event */): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.GuildWarIsNotice, false));
            return;
        }

        public updateGuildWarState(arg1: EGuildwarState): void
        {
            var state: EGuildwarState;

            var loc1;
            state = arg1;
            this._state = state;
            if (state != EGuildwarState.SignUp) 
            {
                if (state != EGuildwarState.Enter) 
                {
                    if (state != EGuildwarState.Open) 
                    {
                        this._btnEnter.enabled = false;
                    }
                    else if (Cache.instance.guildWar.guildwarEnter && Cache.instance.guildWar.guildwarEnter.canEnter && ClockManager.instance.nowDate.time < Cache.instance.guildWar.guildwarEnter.endDt.time) 
                    {
                        with ({}) 
                        {
                        };
                        
#error('pushwith') {}
                        .flash.utils.setTimeout(
#error('pushwith') {}
                        .closeTips = (): void
                        {
                            _btnEnter.enabled = false;
                            _btnSignUp.enabled = false;
                            _tfLeftTime.text = Language.getString(41876);
                            return;
                        }, Cache.instance.guildWar.guildwarEnter.endDt.time - ClockManager.instance.nowDate.time)
                    }
                    else 
                    {
                        this._btnEnter.enabled = false;
                        this._btnSignUp.enabled = false;
                        this._tfLeftTime.text = Language.getString(41876);
                    }
                }
                else 
                {
                    this._btnEnter.enabled = true;
                    this._btnSignUp.enabled = false;
                    this._tfLeftTime.setParse(Language.getString(41875));
                }
            }
            else 
            {
                this._btnEnter.enabled = false;
                if (Cache.instance.guildWar.guildWarSignUpInfo) 
                {
                    this._btnSignUp.enabled = !Cache.instance.guildWar.guildWarSignUpInfo.isSignUp;
                }
                else 
                {
                    this._btnSignUp.enabled = true;
                }
                this._tfLeftTime.setParse(Language.getString(41874));
            }
            return;
        }

        public resetbtnState(): void
        {
            var loc1=!(Cache.instance.guild.myGuildInfo == null);
            this._spHaveGuild.visible = loc1;
            this._spNotHaveGuild.visible = !loc1;
            return;
        }

        public reset(): void
        {
            this._btnSignUp.label = Language.getString(41873);
            this._btnSignUp.enabled = true;
            this.resetbtnState();
            return;
        }

        public updateSignUpInfo(arg1: SGuildWarSingUpInfo): void
        {
            this._tfSignUpNumber.htmlText = Language.getStringByParam(41872, arg1.players.length.toString());
            if (arg1.isSignUp) 
            {
                this._btnSignUp.label = Language.getString(41835);
                this._btnSignUp.enabled = false;
            }
            else 
            {
                this._btnSignUp.label = Language.getString(41873);
                this._btnSignUp.enabled = true;
            }
            if (GuildwarSignListWindow.hasInstance()) 
            {
                GuildwarSignListWindow.instance.updateData(arg1);
            }
            return;
        }

        protected /* override */ createChildren(): void
        {
            super.createChildren();
            this.createBg();
            this.createLeftTopPart();
            this.createLeftBottomPart();
            this.createRightPart();
            this.resetbtnState();
            LoaderHelp.addResCallBack(ResFileConst.guildWarEnter, this.resGuildWarEnterComplete);
            LoaderHelp.addResCallBack(ResFileConst.exchange, this.resExchangeComplete);
            var loc1=0;
            if (Cache.instance.guild.myGuildInfo) 
            {
                loc1 = Cache.instance.guild.myGuildInfo.contribution;
            }
            this.updateContribution(loc1);
            return;
        }

        /* internal  */createBg(): void
        {
            ObjCreate.createBg(17, 38, 330, 142, this);
            ObjCreate.createBg(17, 184, 330, 277, this);
            ObjCreate.createBg(349, 38, 277, 423, this);
            return;
        }

        /* internal  */createLeftTopPart(): void
        {
            this._spTipContainer = new Object /* flash.display.Sprite */();
            this._spTipContainer.x = 14;
            this._spTipContainer.y = 40;
            this._spTipContainer.mouseEnabled = false;
            this.addChild(this._spTipContainer);
            var loc1=new GTextFormat(FontUtil.songtiName, 12, 11661311);
            loc1.leading = 7;
            loc1.indent = 24;
            this._tfTitle = ObjCreate.createTextField(Language.getString(41602), 11, 10, 90, 20, this._spTipContainer, new GTextFormat(FontUtil.songtiName, 12, 64767));
            this._tfContent = ObjCreate.createTextField("", 11, 33, 320, 65, this._spTipContainer, loc1);
            this._tfContent.wordWrap = true;
            this._tfContent.mouseEnabled = false;
            this._tfContent.htmlText = Language.getString(41859);
            this._tfTime = ObjCreate.createTextField(Language.getString(41860), 11, 110, 320, 20, this._spTipContainer, new GTextFormat(FontUtil.songtiName, 12, 65280));
            return;
        }

        /* internal  */createRewardSp(arg1: string, arg2: int, arg3: int): Object /* flash.display.Sprite */
        {
            var loc1;
            (loc1 = new Object /* flash.display.Sprite */()).mouseEnabled = false;
            loc1.mouseChildren = false;
            var loc2=ObjCreate.createTextField("", 0, 0, 75, 20, loc1);
            var loc3=ObjCreate.createTextField("", 75, 0, 120, 20, loc1);
            var loc4=ObjCreate.createTextField("", 193, 0, 120, 20, loc1);
            loc2.htmlText = arg1;
            loc3.htmlText = Language.getStringByParam(41877, arg2.toString());
            loc4.htmlText = Language.getStringByParam(41878, arg3.toString());
            return loc1;
        }

        /* internal  */onLookTopHandler(arg1: Object /* flash.events.TextEvent */): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.RankSelectedAssignType, {"oneIdx": 1, "twoIdx": 2}));
            return;
        }

        /* internal  */createRightPart(): void
        {
            var loc3=null;
            var loc9=null;
            this._rightPart = new Object /* flash.display.Sprite */();
            ObjCreate.setObjAttri(this._rightPart, 349, 38, -1, -1, this);
            var loc1=GlobalClass.getBitmap(ImagesConst.TileBg);
            ObjCreate.setObjAttri(loc1, 3, 3, -1, -1, this._rightPart);
            ObjCreate.createTextField(Language.getString(41879), 9, 9, 200, 29, this._rightPart, GlobalStyle.textFormat6);
            var loc2=Cache.instance.role.entityInfo.level >= 60 ? 14011593 : 14011592;
            loc3 = this.createRewardsSp(this._bmpRank1, loc2, Language.getString(41880), 2);
            ObjCreate.setObjAttri(loc3, 15, 27, -1, -1, this._rightPart);
            loc3 = this.createRewardsSp(this._bmpRank23, loc2, Language.getString(41881));
            ObjCreate.setObjAttri(loc3, 15, 87, -1, -1, this._rightPart);
            loc3 = this.createRewardsSp(this._bmpRank45, loc2, Language.getString(41882));
            ObjCreate.setObjAttri(loc3, 15, 147, -1, -1, this._rightPart);
            ObjCreate.createBg(10, 210, 255, 2, this._rightPart, "SplitLine");
            var loc4=ObjCreate.createBitmap(ImagesConst.PackItemBg, 13, 217, this._rightPart);
            ObjCreate.setObjAttri(this._bmpContributeImg, 16, 220, -1, -1, this._rightPart);
            ObjCreate.setObjAttri(this._bmpGuildContribute, 57, 216, -1, -1, this._rightPart);
            this._myContribute = ObjCreate.createTextField("", 60, 236, 120, 20, this._rightPart);
            ObjTeamCreate.setTextFieldKeyValue(this._myContribute, Language.getString(41637), "0", "#00FF00", "#f0ea3f");
            this._goToExchange = ObjCreate.createGButton(Language.getString(41883), 168, 215, 110, 20, this._rightPart, "LinkButton");
            this._goToExchange.addEventListener(flash.events.MouseEvent.CLICK, this.onGoToExchangeHandler);
            ObjCreate.createBitmap(ImagesConst.Fire, 13, 250, this._rightPart);
            var loc5;
            (loc5 = ObjCreate.createTextField("", 35, 258, 240, 20, this._rightPart, GlobalStyle.textFormatGreen)).htmlText = Language.getString(41884);
            this._aryBgItem = new Array<any>();
            var loc6=0;
            while (loc6 < 12) 
            {
                (loc9 = new BgItem()).x = 17 + 40 * loc6 % 6;
                loc9.y = 277 + int(loc6 / 6) * 40;
                this._rightPart.addChild(loc9);
                this._aryBgItem.push(loc9);
                ++loc6;
            }
            ObjCreate.createBg(10, 358, 255, 2, this._rightPart, "SplitLine");
            var loc7;
            (loc7 = ObjCreate.createTextField("", 12, 367, 270, 20, this._rightPart)).htmlText = Language.getString(41885);
            var loc8;
            (loc8 = GlobalStyle.textFormat1).leading = 5;
            (loc5 = ObjCreate.createTextField("", 15, 385, 252, 40, this._rightPart, loc8)).multiline = true;
            loc5.wordWrap = true;
            loc5.htmlText = Language.getString(41886);
            this._tfLookTop = ObjCreate.createTextField("", 195, 402, 90, 20, this._rightPart, GlobalStyle.textFormatGreen);
            this._tfLookTop.htmlText = Language.getString(41642);
            this._tfLookTop.addEventListener(flash.events.TextEvent.LINK, this.onLookTopHandler);
            this.updateItem();
            return;
        }

        /* internal  */resGuildWarEnterComplete(): void
        {
            this._bmpRank1.bitmapData = GlobalClass.getBitmapData(ImagesConst.GuildWarRank1);
            this._bmpRank23.bitmapData = GlobalClass.getBitmapData(ImagesConst.GuildWarRank23);
            this._bmpRank45.bitmapData = GlobalClass.getBitmapData(ImagesConst.GuildWarRank45);
            return;
        }

        /* internal  */resExchangeComplete(): void
        {
            this._bmpContributeImg.bitmapData = GlobalClass.getBitmapData(ImagesConst.contriImg);
            this._bmpGuildContribute.bitmapData = GlobalClass.getBitmapData(ImagesConst.title_gongxian);
            return;
        }

        /* internal  */onGoToExchangeHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.GuildOpenShop));
            return;
        }

        /* internal  */onFlyFootClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            AIManager.onAIControl(Cache.instance.scene.getNpcByEffect(ENpcEffect._ENpcGuildDailyGift), AIType.AI_Convey);
            return;
        }

        /* internal  */createRewardsSp(arg1: Object /* flash.display.Bitmap */, arg2: int, arg3: string, arg4: int=1): Object /* flash.display.Sprite */
        {
            var loc1=new Object /* flash.display.Sprite */();
            arg1.y = 6;
            loc1.addChild(arg1);
            var loc2;
            (loc2 = ObjCreate.createTextField("", 0, 30, 100, 20, loc1)).htmlText = arg3;
            var loc3=new ItemData(arg2);
            var loc4;
            (loc4 = ObjCreate.createTextField("", 100, 30, 90, 20, loc1)).htmlText = ItemsUtil.getItemName(loc3);
            var loc5;
            (loc5 = new BgItem()).setItemCode(arg2, arg4);
            ObjCreate.setObjAttri(loc5, 190, 19, -1, -1, loc1);
            return loc1;
        }

        /* internal  */updateItem(): void
        {
            var loc3=null;
            var loc1=[19012000, 19012001, 19022000, 19022001, 19052000, 19052001, 14031003, 14102300, 14102306, 14105301, 14076201, 13600001];
            var loc2=0;
            while (loc2 < this._aryBgItem.length) 
            {
                loc3 = this._aryBgItem[loc2];
                loc3.setItemCode(int(loc1[loc2]));
                ++loc2;
            }
            return;
        }

        public updateContribution(arg1: int): void
        {
            ObjTeamCreate.setTextFieldKeyValue(this._myContribute, Language.getString(41887), arg1.toString(), "#00FF00", "#f0ea3f");
            return;
        }

        public static get instance(): GuildwarEnterWindow
        {
            if (!GuildwarEnterWindow._instance) 
            {
                GuildwarEnterWindow._instance = new GuildwarEnterWindow();
            }
            return GuildwarEnterWindow._instance;
        }

        /* internal  */createLeftBottomPart(): void
        {
            var loc1=new Object /* flash.display.Sprite */();
            ObjCreate.setObjAttri(loc1, 21, 186, -1, -1, this);
            this._spHaveGuild = new Object /* flash.display.Sprite */();
            ObjCreate.setObjAttri(this._spHaveGuild, 0, 0, -1, -1, loc1);
            this._tfTextGuildWarSignUp = ObjCreate.createTextField(Language.getString(41861), 40, 10, 100, 20, this._spHaveGuild, GlobalStyle.textFormat6);
            this._btnSignUp = ObjCreate.createGButton(Language.getString(41889), 37, 45, 60, 26, this._spHaveGuild);
            this._tfEnterGuildWar = ObjCreate.createTextField(Language.getString(41862), 220, 10, 100, 20, this._spHaveGuild, GlobalStyle.textFormat6);
            this._btnEnter = ObjCreate.createGButton(Language.getString(41890), 225, 45, 60, 26, this._spHaveGuild);
            this._btnEnter.enabled = false;
            this._tfSignUpNumber = ObjCreate.createTextField(Language.getString(41863), 112, 52, 115, 20, this._spHaveGuild, GlobalStyle.textFormatGreen);
            this._spNotHaveGuild = new Object /* flash.display.Sprite */();
            this._spNotHaveGuild.visible = false;
            loc1.addChild(this._spNotHaveGuild);
            var loc2=GlobalStyle.textFormat6;
            loc2.leading = 7;
            this._tfNothaveguildTips = ObjCreate.createTextField("", 28, 14, 275, 40, this._spNotHaveGuild, loc2);
            this._tfNothaveguildTips.multiline = true;
            this._tfNothaveguildTips.wordWrap = true;
            this._tfNothaveguildTips.htmlText = Language.getString(41864);
            this._btnAddGuild = ObjCreate.createGButton(Language.getString(41865), 116, 60, 70, 26, this._spNotHaveGuild);
            this._tfLeftTime = new SecTimerView();
            this._tfLeftTime.mouseEnabled = false;
            var loc3=GlobalStyle.textFormat6;
            loc3.bold = true;
            this._tfLeftTime.defaultTextFormat = loc3;
            ObjCreate.setObjAttri(this._tfLeftTime, 80, 95, 170, 20, loc1);
            this._btnSignList = ObjCreate.createGButton(Language.getString(41891), 200, 90, 70, 24, loc1, "LinkButton");
            ObjCreate.createBg(15, 122, 305, 2, loc1, "SplitLine");
            var loc4=GlobalClass.getBitmap(ImagesConst.TileBg);
            ObjCreate.setObjAttri(loc4, 7, 125, -1, -1, loc1);
            ObjCreate.createTextField(Language.getString(41866), 10, 129, 200, 20, loc1, GlobalStyle.textFormat6);
            var loc5=this.createRewardSp(Language.getString(41867), 300, 1000);
            var loc6=this.createRewardSp(Language.getString(41868), 240, 800);
            var loc7=this.createRewardSp(Language.getString(41869), 200, 600);
            var loc8=this.createRewardSp(Language.getString(41870), 160, 500);
            var loc9=this.createRewardSp(Language.getString(41871), 120, 400);
            ObjCreate.setObjAttri(loc5, 7, 155, -1, -1, loc1);
            ObjCreate.setObjAttri(loc6, 7, 180, -1, -1, loc1);
            ObjCreate.setObjAttri(loc7, 7, 205, -1, -1, loc1);
            ObjCreate.setObjAttri(loc8, 7, 230, -1, -1, loc1);
            ObjCreate.setObjAttri(loc9, 7, 255, -1, -1, loc1);
            this._btnSignUp.addEventListener(flash.events.MouseEvent.CLICK, this.onBtnSignUpClick);
            this._btnAddGuild.addEventListener(flash.events.MouseEvent.CLICK, this.onBtnAddGuildClick);
            this._btnEnter.addEventListener(flash.events.MouseEvent.CLICK, this.onBtnEnterClick);
            this._btnSignList.addEventListener(flash.events.MouseEvent.CLICK, this.onClickSignList);
            return;
        }

        /* internal  */onBtnSignUpClick(arg1: Object /* flash.events.MouseEvent */): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.GuildwarSignUp));
            return;
        }

        /* internal  */onBtnAddGuildClick(arg1: Object /* flash.events.MouseEvent */): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.GuildListWindowOpen));
            return;
        }

        /* internal  */onBtnEnterClick(arg1: Object /* flash.events.MouseEvent */): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.GuildWarEnterClick));
            return;
        }

        /* internal  */onClickSignList(arg1: Object /* flash.events.MouseEvent */): void
        {
            GuildwarSignListWindow.instance.layer = this;
            GuildwarSignListWindow.instance.show();
            GuildwarSignListWindow.instance.x = 642;
            GuildwarSignListWindow.instance.y = 0;
            if (Cache.instance.guildWar.guildWarSignUpInfo) 
            {
                GuildwarSignListWindow.instance.updateData(Cache.instance.guildWar.guildWarSignUpInfo);
            }
            return;
        }

        public updateEndTime(arg1: Date): void
        {
            this._tfLeftTime.setLeftTime(int((arg1.time - ClockManager.instance.nowDate.time) / 1000));
            return;
        }

        public static hasInstance(): Boolean
        {
            return !(GuildwarEnterWindow._instance == null);
        }

        /* internal */ /* var */_spTipContainer: Object /* flash.display.Sprite */;

        /* internal */ /* var */_tfTitle: Object /* flash.text.TextField */;

        /* internal */ /* var */_tfContent: Object /* flash.text.TextField */;

        /* internal */ /* var */_spHaveGuild: Object /* flash.display.Sprite */;

        /* internal */ /* var */_tfTextGuildWarSignUp: Object /* flash.text.TextField */;

        /* internal */ /* var */_btnSignUp: GButton;

        /* internal */ /* var */_tfEnterGuildWar: Object /* flash.text.TextField */;

        /* internal */ /* var */_btnEnter: GButton;

        /* internal */ /* var */_tfSignUpNumber: Object /* flash.text.TextField */;

        /* internal */ /* var */_spNotHaveGuild: Object /* flash.display.Sprite */;

        /* internal */ /* var */_tfNothaveguildTips: Object /* flash.text.TextField */;

        /* internal */ /* var */_btnAddGuild: GButton;

        /* internal */ /* var */_tfLeftTime: SecTimerView;

        /* internal */ /* var */_btnSignList: GButton;

        /* internal */ /* var */_state: EGuildwarState;

        /* internal */ /* var */_rightPart: Object /* flash.display.Sprite */;

        /* internal */ /* var */_bmpRank1: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_bmpRank23: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_bmpRank45: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_bmpContributeImg: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_tfTime: Object /* flash.text.TextField */;

        /* internal */ /* var */_bmpGuildContribute: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_myContribute: Object /* flash.text.TextField */;

        /* internal */ /* var */_goToExchange: GButton;

        /* internal */ static /* var */_instance: GuildwarEnterWindow;

        /* internal */ /* var */_aryBgItem: Array<any>;

        /* internal */ /* var */_tfLookTop: Object /* flash.text.TextField */;
    }
